#include "rrrotatey.h"
#include <cmath>
#include <cstdio>

RRRotateY::RRRotateY()
{
    degree = 0.0f;
}

void RRRotateY::rrSetDegree(float deg)
{
    degree = deg;
}

void RRRotateY::rrRotateY(RRPrim *arg)
{
    RRVertex *vp;
    float x, z;
    float nx, nz;
    int vnum;
    vnum = arg->rrGetVertsNum();
    for(int i=0; i<vnum; i++) {
        vp = arg->rrGetVertAdrs(i);
        x = vp->x * cosf(degree * 3.14159 / 180.0) + vp->z * sinf(degree * 3.14159 / 180.0);
        z = vp->z * cosf(degree * 3.14159 / 180.0) - vp->x * sinf(degree * 3.14159 / 180.0);
        vp->x = x;
        vp->z = z;
        nx = vp->nx * cosf(degree * 3.14159 / 180.0) + vp->nz * sinf(degree * 3.14159 / 180.0);
        nz = vp->nz * cosf(degree * 3.14159 / 180.0) - vp->nx * sinf(degree * 3.14159 / 180.0);
        vp->nx = nx;
        vp->nz = nz;
        //printf("%f, %f\n", vp->nx, vp->nz);
    }
}
